from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin, GroupAdmin
from .models import UserProfile, PasswordResetCode


class UserProfileAdmin(BaseUserAdmin):
    list_display = ('username','nickname','email','identity','source','is_staff','is_superuser','is_active','last_login')
    # 这里可以自定义Admin的显示方式
    fieldsets = (
        ('用户名与密码', {'fields': ('username', 'password')}),
        ('用户信息', {'fields': ('nickname', 'email', 'avatar','bio', 'address', 'source','identity')}),
        ('社交信息', {'fields': ('phone',  'weibo', 'qq','wechat','github','gitee','website' )}),
        ('社交二维码', {'fields': ('qq_qrcode', 'wechat_qrcode', 'wechat_gzh_qrcode')}),
        ('权限设置', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),
        ('时间信息', {'fields': ('last_login','created_date', 'modified_date')}),
    )
    # 添加搜索和过滤功能
    search_fields = ('username', 'nickname', 'email','identity')
    ordering = ('username',)
    filter_horizontal = ('groups', 'user_permissions',)
    list_editable = ('is_staff', 'is_superuser', 'is_active','identity')

admin.site.register(UserProfile, UserProfileAdmin)

@admin.register(PasswordResetCode)
class PasswordResetCodeAdmin(admin.ModelAdmin):
    list_display = ('email', 'code', 'created_date', 'is_used')
    search_fields = ('email', 'code')
    list_filter = ('is_used',)
    ordering = ('-created_date',)